#pragma once

namespace mpk_internal_system {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace MySql::Data::MySqlClient;

	/// <summary>
	/// Summary for BusStopDistribution
	/// </summary>
	public ref class BusStopDistribution : public System::Windows::Forms::Form
	{
	public:
		bool succeed_distr;
		BusStopDistribution(void)
		{
			InitializeComponent();
			
			succeed_distr = false;
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~BusStopDistribution()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  menu;
	private: System::Windows::Forms::DataGrid^  dataGrid1;
	private: System::Windows::Forms::Button^  display;
	private: System::Windows::Forms::ComboBox^  comboBox1;
	private: System::Windows::Forms::Label^  label1;
	protected: 

	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->menu = (gcnew System::Windows::Forms::Button());
			this->dataGrid1 = (gcnew System::Windows::Forms::DataGrid());
			this->display = (gcnew System::Windows::Forms::Button());
			this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dataGrid1))->BeginInit();
			this->SuspendLayout();
			// 
			// menu
			// 
			this->menu->Location = System::Drawing::Point(278, 280);
			this->menu->Name = L"menu";
			this->menu->Size = System::Drawing::Size(75, 23);
			this->menu->TabIndex = 0;
			this->menu->Text = L"Menu";
			this->menu->UseVisualStyleBackColor = true;
			this->menu->Click += gcnew System::EventHandler(this, &BusStopDistribution::menu_Click);
			// 
			// dataGrid1
			// 
			this->dataGrid1->DataMember = L"";
			this->dataGrid1->HeaderForeColor = System::Drawing::SystemColors::ControlText;
			this->dataGrid1->Location = System::Drawing::Point(145, 12);
			this->dataGrid1->Name = L"dataGrid1";
			this->dataGrid1->Size = System::Drawing::Size(208, 262);
			this->dataGrid1->TabIndex = 1;
			// 
			// display
			// 
			this->display->Location = System::Drawing::Point(64, 251);
			this->display->Name = L"display";
			this->display->Size = System::Drawing::Size(75, 23);
			this->display->TabIndex = 2;
			this->display->Text = L"Display";
			this->display->UseVisualStyleBackColor = true;
			this->display->Click += gcnew System::EventHandler(this, &BusStopDistribution::display_Click);
			// 
			// comboBox1
			// 
			this->comboBox1->FormattingEnabled = true;
			this->comboBox1->Location = System::Drawing::Point(15, 41);
			this->comboBox1->Name = L"comboBox1";
			this->comboBox1->Size = System::Drawing::Size(121, 21);
			this->comboBox1->TabIndex = 3;
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(12, 12);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(89, 26);
			this->label1->TabIndex = 4;
			this->label1->Text = L"Choose bus stop \r\ndistribution:";
			// 
			// BusStopDistribution
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(362, 315);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->comboBox1);
			this->Controls->Add(this->display);
			this->Controls->Add(this->dataGrid1);
			this->Controls->Add(this->menu);
			this->Name = L"BusStopDistribution";
			this->Text = L"BusStopDistribution";
			this->Load += gcnew System::EventHandler(this, &BusStopDistribution::BusStopDistribution_Load);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dataGrid1))->EndInit();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void menu_Click(System::Object^  sender, System::EventArgs^  e) {
				 succeed_distr = true;
			 }
	private: System::Void display_Click(System::Object^  sender, System::EventArgs^  e) {
				System::String ^ strCon = "datasource=localhost;username=root;password=;database=mpk_db";

				MySqlConnection ^ conDatabase = gcnew MySqlConnection(strCon);

				int index = comboBox1->SelectedIndex;
				index++;
				//create a mysql DataAdapter
				System::String ^ strAdap = "Select rozklad.godzina, polaczenie.id_linii from polaczenie, rozklad where polaczenie.id_rozklad=rozklad.id_rozklad and polaczenie.id_przystanek=" + index + " ORDER BY polaczenie.id_linii";
				MySqlDataAdapter ^ myadp = gcnew MySqlDataAdapter(strAdap, conDatabase);

				//create a dataset
				DataSet ^ myds = gcnew DataSet();

				//now fill and bind the DataGrid
				myadp->Fill(myds, "rozklad");
				dataGrid1->DataSource = myds->Tables["rozklad"]->DefaultView;
				dataGrid1->SetDataBinding(myds, "rozklad");
			 }
	private: System::Void BusStopDistribution_Load(System::Object^  sender, System::EventArgs^  e) {
				System::String ^ strCon = "datasource=localhost;username=root;password=;database=mpk_db";

				MySqlConnection ^ conDatabase = gcnew MySqlConnection(strCon);
				MySqlCommand    ^ cmdDatabase = gcnew MySqlCommand("SELECT * FROM przystanek;", conDatabase);

				conDatabase->Open();

				MySqlDataReader ^ myReader;
				myReader = cmdDatabase->ExecuteReader();

				while (myReader->Read()) {
					System::String ^ strCombo = myReader->GetString(1) + " --> " + myReader->GetString(2);
					comboBox1->Items->Add(strCombo);
				}

   
				myReader->Close();

				conDatabase->Close();
			 }
};
}
